<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
</head>
<body>

<div id="view"></div>

<script id="demo2" type="text/html">
    <h3>{{ d.title }}</h3>
    <ul>
        {{# layui.each(d.list, function(index, item){ }}
        <li>
            <span>{{ item.modname }}</span>
            <span>{{ item.alias }}：</span>
            <span>{{ item.site || '' }}</span>
        </li>
        {{# }); }}
        {{# if(d.list.length === 0){ }}
        无数据
        {{# } }}
    </ul>
</script>
<script src="../layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'jquery', 'laytpl'], function () {
        var layer = layui.layer
            , form = layui.form
            , $ = layui.jquery
            , laytpl = layui.laytpl;

        var data = { //数据
            "title": "Layui常用模块"
            , "list": [
                {"modname": "弹层", "alias": "layer", "site": "layer.layui.com"},
                {"modname": "表单", "alias": "form"}
            ]
        };
        
        var getTpl = $("#demo2").html();
        var view = $("#view");
        laytpl(getTpl).render(data, function (html) {
            view.html(html);
        });

    });
</script>
</body>
</html>